package com.fhminyi.util;

import com.fhminyi.model.Product;
import javax.swing.*;
import java.io.File;
import java.io.IOException;

public class ImageUploadSelector {
    private File selectedFile;

    public void showFileChooser(JFrame parentFrame) {
        JFileChooser fileChooser = new JFileChooser();
        fileChooser.setDialogTitle("选择图片文件");
        fileChooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
        int result = fileChooser.showOpenDialog(parentFrame);
        if (result == JFileChooser.APPROVE_OPTION) {
            selectedFile = fileChooser.getSelectedFile();
        }
    }

    public File getSelectedFile() {
        return selectedFile;
    }

    public void uploadProductImage(Product product) throws IOException {
        if (selectedFile != null) {
            ProductImageUploadUtil.uploadProductImage(selectedFile, product);
        }
    }
}